package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.OrderDetail;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Mapper
public interface OrderMapper {

    //插入数据库
    void insertOrder(Orders orders);

    // 批量插入
    void insertOrderDetails(List<OrderDetail> orderDetailList);

    /**
     * 根据订单号和用户id查询订单
     * @param orderNumber
     * @param userId
     */
    @Select("select * from orders where number = #{orderNumber} and user_id= #{userId}")
    Orders getByNumberAndUserId(String orderNumber, Long userId);

    /**
     * 修改订单信息
     * @param orders
     */
    void update(Orders orders);

    /**
     * 接单
     * @param orders
     */
    void updateOrderStatus(Orders orders);

    Page<Orders> selectAll(OrdersPageQueryDTO ordersPageQueryDTO);

    //查询订单详情
    @Select("select * from orders where id=#{id}")
    Orders getById(Long id);

    @Select("select * from orders where status = #{status} and order_time = #{ordertime}")
    List<Orders> getByStatusAndOrderTime(@Param("status") Integer status, @Param("time") LocalDateTime time);

    // 查询每天的营业额
    Double selectByMap(Map queryParam);

    // 订单统计
    Long selectByCount(Map queryParam);

    //top10
    List<GoodsSalesDTO> selectSalesTop10(@Param("begin") LocalDate begin, @Param("end") LocalDate end);
}
